package com.wang.animalkingdom;

import java.util.Scanner;

public class Method {
    public static void load(Animal[] animals){
        System.out.println("动物名字\t\t腿的条数\t\t动物叫声");
        for (int i = 0; i < animals.length; i++) {
            if (animals[i] instanceof Terrestrial){
                String name = animals[i].getName();
                int legNum = ((Terrestrial) animals[i]).getLegNum();
                System.out.print(name + "\t\t" + legNum + "\t\t\t");
                animals[i].shout();
            } else {
                String name = animals[i].getName();
                System.out.print(name + "\t\t" + 0 + "\t\t\t");
                animals[i].shout();
            }
        }
    }

    public static void modify(Animal[] animals, Scanner sc) throws Exception {
        String[] names = new String[3];
        int[] legNum = new int[3];
        System.out.println("请输入猫的名字：");
        names[0] = sc.next();
        System.out.println("请输入猫腿的条数：");
        legNum[0] = sc.nextInt();
        //判断异常
        if (legNum[0] != 4){
            throw new Exception("输入错误，猫只有四条腿！");
        }
        System.out.println("请输入鸭子的名字：");
        names[1] = sc.next();
        System.out.println("请输入鸭腿的条数：");
        legNum[1] = sc.nextInt();
        //判断异常
        if (legNum[1] != 2){
            throw new Exception("输入错误，鸭子只有两条腿！");
        }
        System.out.println("请输入海豚的名字：");
        names[2] = sc.next();
        animals[0] = new Cat(names[0], legNum[0]);
        animals[1] = new Duck(names[1], legNum[1]);
        animals[2] = new Dolphin(names[2]);
    }
}
